import { defineStore } from 'pinia';
import request from '@/api/index';
import { LocationQueryValue } from 'vue-router';
export const userStore = defineStore('user', {
  state: () => ({
    activity:4 as number,
    user_id:'' as LocationQueryValue | LocationQueryValue[],
    weekNow:[] as Array<any>, //本周
    weekLast:[] as Array<any>, //上周
    lastWinner:{} as any, // 周星擂主
  }),
  actions: {
    async getActInfo () {
      const res = await request.config()
      const { list={}, now_time } = res.data
      const { weekNow=[], weekLast=[] } = list
      this.weekNow = this.filtersWeekList(weekNow)
      this.weekLast = this.filtersWeekList(weekLast)
    },
    filtersWeekList(obj:any={}) {
      const { 
        gift1=0, giftImg1='', giftName1='', giftPrice1=0,giftType1=1,
        gift2=0, giftImg2='', giftName2='', giftPrice2=0,giftType2=1,
        gift3=0, giftImg3='', giftName3='', giftPrice3=0,giftType3=1,
      } = obj
      let list = [{
        id:gift1,
        image:giftImg1,
        name:giftName1,
        price:giftPrice1,
        tipsType:giftType1,
      },{
        id:gift2,
        image:giftImg2,
        name:giftName2,
        price:giftPrice2,
        tipsType:giftType2,
      },{
        id:gift3,
        image:giftImg3,
        name:giftName3,
        price:giftPrice3,
        tipsType:giftType3,
      }] as Array<any>
      return list
    },
    setLastWinUser(obj:any={}) {
      this.lastWinner = obj
    }
  },
})